package com.lzw.DailyAudit.service.dateAggregation_02.DailyAudit.service.generateInvoices_03;


import com.hooya.fa.eu.biz.DailyAudit.entity.DailyAuditStatus;
import com.hooya.fa.eu.biz.DailyAudit.mapper.DailyAuditStatusMapper;
import com.hooya.fa.eu.biz.DailyAudit.mapper.DailyStkOrigDataCollectMapper;
import com.hooya.fa.eu.biz.DailyAudit.service.dateAggregation_02.CommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
public class Update_InvoiceNo {

    @Autowired
    private DailyStkOrigDataCollectMapper stkOrigdataCollectMapper;

	@Autowired
	private DailyAuditStatusMapper statusMapper;

	@Autowired
	private CommonService commonService;


	@Transactional
	public void update_invoiceno(String currentDate) {

		String name = "update_invoiceno-03";
		DailyAuditStatus dailyAuditStatus = statusMapper.selectStatus(name, currentDate);
		if(dailyAuditStatus != null && dailyAuditStatus.getFlag() == 1){
			log.info("{} - 该方法已执行，进行跳过！",name);
			return;
		}

		log.info("开始更新发票号，日期为：{}", currentDate);

		// 执行更新SQL
		int updatedCount = stkOrigdataCollectMapper.updateInvoiceNoByInvoiceId(currentDate); // fa_eu_daily.stk_origData_collect a  fa_eu_daily.inv_invoice b

		// 修改执行状态
		commonService.UpdateOrInsertStatus(dailyAuditStatus, name, currentDate);

		log.info("发票号更新完成，共更新 {} 条记录", updatedCount);
	}
}
